﻿<Window x:Class="Beaker.OpenCube.NbtEditor.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:conv="clr-namespace:Beaker.OpenCube.Converters"
        xmlns:nbtconv="clr-namespace:Beaker.OpenCube.NbtEditor.Converters" DataContext="{StaticResource MainViewModel}"
        Title="MainWindow" Height="350" Width="525" Icon="Resources/Logo.png">
	<Window.Resources>
		<conv:BooleanConverter x:Key="BooleanToErrorBack" TrueValue="{StaticResource ErrorBrush}" FalseValue="{StaticResource BackgroundBrush}" />
		<nbtconv:NbtIconConverter x:Key="IconConverter" />
	</Window.Resources>
	<Grid Margin="10">
		<Grid.RowDefinitions>
			<RowDefinition Height="24" />
			<RowDefinition Height="10" />
			<RowDefinition Height="*" />
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="Auto" />
			<ColumnDefinition Width="10" />
			<ColumnDefinition Width="*" />
			<ColumnDefinition Width="10" />
			<ColumnDefinition Width="24" />
		</Grid.ColumnDefinitions>
		<Label Grid.Row="0" Grid.Column="0">File:</Label>
		<TextBox Grid.Row="0" Grid.Column="2" Text="{Binding Path, Mode=TwoWay}" BorderThickness="1" BorderBrush="{Binding IsPathInvalid, Converter={StaticResource BooleanToErrorBack}}" />
		<Button Grid.Row="0" Grid.Column="4" Command="{Binding SelectPathCommand}">...</Button>
		<TreeView Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="5" ItemsSource="{Binding Nodes}">
			<TreeView.ItemTemplateSelector>
				<nbtconv:TreeItemTemplateSelector>
					<nbtconv:TreeItemTemplateSelector.KeyEnumerableValueTemplate>
						<HierarchicalDataTemplate ItemsSource="{Binding Value}">
							<StackPanel Orientation="Horizontal">
								<Image Width="16" Height="16" Source="{Binding Value, Converter={StaticResource IconConverter}}" Margin="0,2,8,2" />
								<TextBlock Text="{Binding Key}" />
							</StackPanel>
						</HierarchicalDataTemplate>
					</nbtconv:TreeItemTemplateSelector.KeyEnumerableValueTemplate>
					<nbtconv:TreeItemTemplateSelector.KeyValueTemplate>
						<DataTemplate>
							<StackPanel Orientation="Horizontal">
								<Image Width="16" Height="16" Source="{Binding Value, Converter={StaticResource IconConverter}}" Margin="0,2,8,2" />
								<TextBlock Text="{Binding Key}" Height="16" Margin="0,2,20,2" />
								<ContentPresenter Content="{Binding Value}" Height="16" />
							</StackPanel>
						</DataTemplate>
					</nbtconv:TreeItemTemplateSelector.KeyValueTemplate>
					<nbtconv:TreeItemTemplateSelector.EnumerableValueTemplate>
						<HierarchicalDataTemplate ItemsSource="{Binding}">
							<StackPanel Orientation="Horizontal">
								<Image Width="16" Height="16" Source="{Binding Converter={StaticResource IconConverter}}" Margin="0,2,8,2" />
							</StackPanel>
						</HierarchicalDataTemplate>
					</nbtconv:TreeItemTemplateSelector.EnumerableValueTemplate>
					<nbtconv:TreeItemTemplateSelector.ValueTemplate>
						<DataTemplate>
							<StackPanel Orientation="Horizontal">
								<Image Width="16" Height="16" Source="{Binding Converter={StaticResource IconConverter}}" Margin="0,2,8,2" />
								<ContentPresenter Content="{Binding}" Height="16" Margin="0,2,20,2" />
							</StackPanel>
						</DataTemplate>
					</nbtconv:TreeItemTemplateSelector.ValueTemplate>
				</nbtconv:TreeItemTemplateSelector>
			</TreeView.ItemTemplateSelector>
		</TreeView>
	</Grid>
</Window>
